Repository navigation
Give new T[a][b] the length of its first dimension - #559
Open
CatarinaGamboa wants to merge 2 commits into
Open
CatarinaGamboa wants to merge 2 commits into
CatarinaGamboa wants to merge 2 commits into
Conversation
A multi-dimensional array creation took the length of its last dimension, so length(g) of new int[2][3] was 3 and wrong programs were accepted. Only the first dimension now sets the length; inner arrays stay unmodelled. Fixes #557 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
Codex review, round 1Codex ran 39 small programs with Result: no soundness bug or crash introduced by this PR. Every wrong outer-length claim was rejected, e.g.
The matching programs and the 1-D controls pass. One finding is pre-existing on main (same output before this PR), so it is out of scope here:
Nothing to fix in this PR. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
Clean-code reviewAudit of the diff with the clean-code-principles checklist (SOLID, DRY, KISS, YAGNI, naming, functions, comments).
Full |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #557
Problem
visitCtNewArraylooped over every dimension expression and kept the last one, sonew int[2][3]gotlength(_) == 3. Programs that relied on the wrong row count were accepted.Fix
Only the first dimension sets the length:
new T[d1][d2]...getslength(_) == d1. Inner arrays are not modelled, so nothing is assumed about their lengths. The other dimension expressions are still visited as before; they are just no longer tied tolength.Array initializers were already right (
new int[][] {{1,2},{3}}has length 2, the number of rows), and 1-D creation is unchanged.Cases checked (by hand, not all added as tests)
Rejected now:
new int[2][3]/new int[2][]/new int[5][6][]/new int[5][6][7]passed where the row count is a later dimension;new int[n][m]againstm;{{1,2,3}}against 3; reassignmentg = new int[2][3]; return and field refinementslength(_) == 3onnew int[2][3];new String[2][4]assigned toObject[][];length(_) > 1withnew int[n][5]and onlyn > 0; inner-row lengths (g[0]against 3) stay unknown.Accepted: the same shapes with the first dimension, initializers, 1-D
new int[9],{1,2},{}.Tests
CorrectStringArrayLengthandErrorStringArrayLengtheach get one 2-D line; both fail on main and pass with the fix. Fullmvn testpasses.🤖 Generated with Claude Code